<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        ul {
            width: 850px;
            margin: 0 auto;
        }
        ul li {
            float: left;
            width: 100px;
            height: 50px;
            line-height: 50px;
            list-style: none;
        }
        a {
            text-decoration: none;
        }
        body {
            background: url('img/14806956.jpg') no-repeat;
            background-size: cover;
        }
    </style>

</head>
<body>
<?php
$conn = mysqli_connect("localhost","root","","abcd");
if (!$conn){
    die("连接数据库失败：" . mysqli_error());
}
header("Content-type:text/html;charset=utf-8");

$sql="select * from user";
$sql=mysqli_query($conn,$sql);
while ($row=mysqli_fetch_array($sql)) {
    @session_start();
    $cengji=$_SESSION['cengji'];
    $username=$_SESSION['username'];
    if($row['cengji']!=1) {
        ?>
        <ul>
            <li><?php echo $row['username'] ?></li>
            <li>原始密码是</li>
            <li><?php echo $row['password'] ?></li>
            <li style="width: 200px">
                <a href="javascript:;" style="font-size: 13px">给用户绑定新的密码以将其查封:</a>
            </li>

            <li style="width: 300px">
                <form action="guanli.php?id=<?php echo $row['uid']; ?>" method="post"
                      onsubmit="return inputCheck(this)">
                    <input type="text" name="text"/><input type="submit" value="一键查封" name="submit"/>
                </form>
            </li>
        </ul>
        <ul style="width: 850px">
            <li style="width: 550px"></li>
            <li style="width: 300px" style="margin-left: 400px">
                <a href="guanli.php?cd=<?php echo $row['uid']; ?>">将该用户设置为管理员</a>
            </li>
        </ul>
        <?php
    }
    if($row['cengji']==1 && $row['username']!=$username) {
        if($row['username']!='che') {
            ?>
            <ul>
                <li style="width: 200px"><?php echo $row['username'] ?></li>
                <li style="width: 600px">该用户是管理员，您暂时没有权限对其进行查封</li>
            </ul>
            <?php
        }
        if($username=='che') {
            ?>
            <ul>
                <li style="width: 350px"></li>
                <li style="width: 500px" style="margin-left: 400px">
                    <a href="guanli.php?md=<?php echo $row['uid']; ?>">取消该用户的管理员权限</a>
                </li>
            </ul>
            <?php
        }
    }
}?>
<div style="position: absolute;top:50px;right: 50px;border-radius: 35px 10px;background-color: aqua;width: 80px;
height: 65px;text-align: center;line-height: 25px;padding-top: 15px">
<a href="gonggao.php">发布站<br/>内公告</a>
</div>
</body>
<script type="text/javascript">
    function inputCheck(logoForm) {
        if(logoForm.text.value=="")
        {
            alert('内容不能为空');
            logoForm.text.focus();
            return false;
        }
    }
</script>
</html>
<?php
$a=@$_GET['id'];
if(isset($_POST['submit']))
{
    $me=$_POST['text'];
    $sqlOne="update user set password='$me' where uid=$a";
    $ht=mysqli_query($conn,$sqlOne);
    if(!$ht)
    {
        echo "<script language='javascript'>alert('失败');</script>";
    }else{
        echo "<script language='javascript'>alert('成功');history.go(-1);</script>";
    }
}

//设置管理员
if(isset($_GET['cd']))
{
    @session_start();
    $username=$_SESSION['username'];
    $cengji=$_SESSION['cengji'];
    $a=$_GET['cd'];
    $updateCengji="update user set cengji=1 WHERE uid=$a";
    mysqli_query($conn,$updateCengji);
    echo "<script language='javascript'>alert('设置成功');location.href='guanli.php';</script>";
}

//取消管理员权限
if(isset($_GET['md']))
{
    @session_start();
    $username=$_SESSION['username'];
    $cengji=$_SESSION['cengji'];
    $a=$_GET['md'];
    $updateCengji="update user set cengji=0 WHERE uid=$a";
    mysqli_query($conn,$updateCengji);
    echo "<script language='javascript'>alert('取消成功');location.href='guanli.php';</script>";
}

?>